/**
  *@File文件:UserFocusController.java
  *@Date日期:2017年7月18日 下午2:17:29
  *@Copyright版权:Corporation 2017
  */
package com.qiaomengapp.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qiaomengapp.bean.ShopGoodWrap;
import com.qiaomengapp.bean.ShopWarp;
import com.qiaomengapp.bean.User;
import com.qiaomengapp.exception.CustomException;
import com.qiaomengapp.service.IUserFocusService;

/**
 * @Description描述:
 * @Author作者 jinxin
 * @Date日期:2017年7月18日
 */
@Controller
@RequestMapping("userFocus")
public class UserFocusController {
	@Autowired
	private IUserFocusService iUserFocusService;

	// 在个人中心显示收藏的商品数量
	@RequestMapping("collectGoodNum")
	@ResponseBody
	public int collectGoodNum(HttpSession session) {
		User user = (User) session.getAttribute("user");
		List<ShopGoodWrap> list = iUserFocusService.select_shopGood(user.getId());
		return list.size();

	}

	// 在个人中心显示收藏的商店数量
	@RequestMapping("collectShopNum")
	@ResponseBody
	public int collectShopNum(HttpSession session) {
		User user = (User) session.getAttribute("user");
		List<ShopWarp> list = iUserFocusService.select_shop(user.getId());
		return list.size();
	}

	// 显示用户所收藏的全部商品
	@RequestMapping("selectCollectGood")
	@ResponseBody
	public List<ShopGoodWrap> selectCollectGood(HttpSession session) {
		User user = (User) session.getAttribute("user");
		List<ShopGoodWrap> list = iUserFocusService.select_shopGood(user.getId());
		return list;
	}

	// 删除用户的收藏商品
	@RequestMapping("deleteCollectGood")
	@ResponseBody
	public void deleteCollectGood(HttpSession session, int shopGoodId) {
		User user = (User) session.getAttribute("user");
		try {
			iUserFocusService.delete_shopGood(user.getId(), shopGoodId);
		} catch (CustomException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
